package com.ls.lserp.modules.job.service;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ls.lserp.common.utils.DateUtils;
import com.ls.lserp.dbaccess.Dao.BarCodeEntityMapper;
import com.ls.lserp.dbaccess.Dao.ContractCustomEntityMapper;
import com.ls.lserp.dbaccess.Dao.ContractCustomOrderEntityMapper;
import com.ls.lserp.dbaccess.Dao.MaterialEntityMapper;
import com.ls.lserp.dbaccess.Dao.OrderEntityMapper;
import com.ls.lserp.dbaccess.Dao.OrderStyleEntityMapper;
import com.ls.lserp.dbaccess.Dao.ProductionItemEntityMapper;
import com.ls.lserp.dbaccess.Dao.StyleCostEntityMapper;
import com.ls.lserp.dbaccess.Dao.StyleEntityMapper;
import com.ls.lserp.dbaccess.Dao.StyleFitEntityMapper;
import com.ls.lserp.dbaccess.Dao.StyleMaterialEntityMapper;
import com.ls.lserp.dbaccess.Dao.StyleOperatingEntityMapper;
import com.ls.lserp.dbaccess.Dao.StyleOptionEntityMapper;
import com.ls.lserp.dbaccess.Dao.StyleQualityControlEntityMapper;
import com.ls.lserp.dbaccess.Dao.StyleQualityDetailsEntityMapper;
import com.ls.lserp.dbaccess.Dao.TempOrderTableEntityMapper;
import com.ls.lserp.dbaccess.Entity.BarCodeEntity;
import com.ls.lserp.dbaccess.Entity.ContractCustomEntity;
import com.ls.lserp.dbaccess.Entity.ContractCustomOrderEntity;
import com.ls.lserp.dbaccess.Entity.OrderEntity;
import com.ls.lserp.dbaccess.Entity.OrderStyleEntity;
import com.ls.lserp.dbaccess.Entity.ProductionItemEntity;
import com.ls.lserp.dbaccess.Entity.StyleEntity;
import com.ls.lserp.dbaccess.Entity.StyleFitEntity;
import com.ls.lserp.dbaccess.Entity.StyleMaterialEntity;
import com.ls.lserp.dbaccess.Entity.StyleOperatingEntity;
import com.ls.lserp.dbaccess.Entity.StyleOptionREntity;
import com.ls.lserp.dbaccess.Entity.StyleQualityControlEntity;
import com.ls.lserp.dbaccess.Entity.StyleQualityDetailsEntity;
import com.ls.lserp.dbaccess.Entity.TempOrderTableEntity;
import com.ls.lserp.modules.order.entity.StyleCostEntity;

/**
 * @ClassName : DataBaseSyncService
 * @Description : ERP与平台数据同步 a_designoption_p
 * @author : zhigang.gao
 * @date : 2017年9月21日
 */
@Service
@Transactional(readOnly = false)
public class ERPOrderSyncService {

	/**
	 * 日志对象
	 */
	protected Logger logger = LoggerFactory.getLogger(getClass());

	@Autowired // 1.c_contract_custom_p 定制合同表
	private ContractCustomEntityMapper contractCustomEntityMapper;

	@Autowired // 2.c_contract_custom_order_r 定制合同订单关联表
	private ContractCustomOrderEntityMapper contractCustomOrderEntityMapper;

	@Autowired // 3.o_order_p 定制订单表
	private OrderEntityMapper orderEntityMapper;

	@Autowired // 4.s_style_p 定制款式表
	private StyleEntityMapper styleEntityMapper;

	@Autowired // 5.temp_order_table 定制订单临时表
	private TempOrderTableEntityMapper tempOrderTableEntityMapper;

	@Autowired // 6.o_order_style_r 定制订单款式关联表
	private OrderStyleEntityMapper orderStyleEntityMapper;

	@Autowired // 7.s_style_fit_r 定制量体表
	private StyleFitEntityMapper styleFitEntityMapper;

	@Autowired // 8.s_style_option_r 定制设计项目表
	private StyleOptionEntityMapper styleOptionEntityMapper;

	@Autowired // 9.s_style_material_s 定制单耗表
	private StyleMaterialEntityMapper styleMaterialEntityMapper;

	@Autowired // 10.s_style_cost_s 定制设计费用表
	private StyleCostEntityMapper styleCostEntityMapper;

	@Autowired // 11.s_style_operating_s 定制设计费用表
	private StyleOperatingEntityMapper styleOperatingEntityMapper;

	@Autowired // 12.s_style_quality_control_p 定制设计费用表
	private StyleQualityControlEntityMapper styleQualityControlEntityMapper;

	@Autowired // 13.a_bar_code_p 定制设计费用表
	private BarCodeEntityMapper barCodeEntityMapper;

	@Autowired
	private ProductionItemEntityMapper productionItemEntityMapper;
	
	@Autowired
	private StyleQualityDetailsEntityMapper styleQualityDetailsEntityMapper;
	
	@Autowired // i_material_customer_p
	private MaterialEntityMapper materialEntityMapper;

	/**
	 * 获取合同数据并更新同步状态
	 * 
	 * @Title : findContractData
	 * @Description : TODO
	 * @param flag true则更新状态，false则反之
	 * @return
	 * @throws Exception
	 * @return : List<ContractCustomEntity>
	 *
	 * @author : GavinGao
	 * @date : 2018年8月1日
	 */
	public List<ContractCustomEntity> findContractData(boolean flag) throws Exception {
		List<ContractCustomEntity> contractCustomList = contractCustomEntityMapper
				.findContractList(new ContractCustomEntity());
		if (flag) {
			updateSyncStatus(contractCustomList);
		}
		return contractCustomList;
	}

	/**
	 * 获取同步数据
	 * 
	 * @return
	 * @throws Exception
	 */
	public Map<String, Object> getSyncData(List<ContractCustomEntity> contractCustomList) throws Exception {
		logger.info("/-------------------------数据读取-------------" + DateUtils.getDate("yyyy-MM-dd HH:mm:ss")
				+ "--------------开始--------------------------------------------------/");
		// 返回数据map对象
		Map<String, Object> returnMap = new HashMap<>();
		// s_style_option_r 数据map对象
		Map<String, List<StyleOptionREntity>> styleOptionMap = new HashMap<>();
		// s_style_material_s 数据map对象
		Map<String, List<StyleMaterialEntity>> styleMaterialMap = new HashMap<>();
		// s_style_cost_s 数据map对象
		Map<String, List<StyleCostEntity>> styleCostMap = new HashMap<>();
		// s_style_operating_s 数据map对象
		Map<String, List<StyleOperatingEntity>> styleOperatingMap = new HashMap<>();
		// s_style_quality_control_p 数据map对象
		Map<String, List<StyleQualityControlEntity>> styleQualityControlMap = new HashMap<>();
		
		// 1.c_contract_custom_p
		// List<ContractCustomEntity> contractCustomList = null;
		// 2.c_contract_custom_order_r
		List<ContractCustomOrderEntity> contractCustomOrderList = new ArrayList<ContractCustomOrderEntity>();
		// 3.o_order_p
		List<OrderEntity> orderList = new ArrayList<OrderEntity>();
		// 4.s_style_p
		List<StyleEntity> styleList = new ArrayList<StyleEntity>();
		// 5.temp_order_table
		List<TempOrderTableEntity> tempOrderTableList = new ArrayList<TempOrderTableEntity>();
		// 6.o_order_style_r
		List<OrderStyleEntity> orderStyleList = new ArrayList<OrderStyleEntity>();
		// 7.s_style_fit_r
		List<StyleFitEntity> styleFitList = new ArrayList<StyleFitEntity>();
		// 8.s_style_option_r
		List<StyleOptionREntity> styleOptionList = new ArrayList<StyleOptionREntity>();
		// 9.s_style_material_s
		List<StyleMaterialEntity> styleMaterialList = new ArrayList<StyleMaterialEntity>();
		// 10.s_style_cost_s
		List<StyleCostEntity> styleCostList = new ArrayList<StyleCostEntity>();
		// 11.s_style_operating_s
		List<StyleOperatingEntity> styleOperatingList = new ArrayList<StyleOperatingEntity>();
		// 12.s_style_quality_control_p
		List<StyleQualityControlEntity> styleQualityControlList = new ArrayList<StyleQualityControlEntity>();
		// 13.a_bar_code_p
		List<BarCodeEntity> barCodeList = new ArrayList<BarCodeEntity>();
		// ---1---------------------------------------------------------------------------------------//
		// 查询出为同步的合同数据集
		// contractCustomList = contractCustomEntityMapper.findContractList(new
		// ContractCustomEntity());
		// ---1---------------------------------------------------------------------------------------//
		// 存在数据则继续执行
		if (contractCustomList != null && contractCustomList.size() > 0) {
			// 遍历获取其他合同相关数据
			for (ContractCustomEntity contractEntity : contractCustomList) {
				// ---2---------------------------------------------------------------------------------------//
				// 获取合同订单关联数据
				List<ContractCustomOrderEntity> contractCustomOrderTempList = contractCustomOrderEntityMapper
						.findListByContractId(contractEntity.getContractId());
				// 存在数据则继续执行
				if (contractCustomOrderTempList != null && contractCustomOrderTempList.size() > 0) {
					// 将合同订单关联数据集放入对应总集合对象中
					contractCustomOrderList.addAll(contractCustomOrderTempList);
					// ---2---------------------------------------------------------------------------------------//
					// 遍历获取订单及其他相关数据
					for (ContractCustomOrderEntity customOrderEntity : contractCustomOrderTempList) {
						// ---3---------------------------------------------------------------------------------------//
						// 获取订单信息数据
						OrderEntity orderEntity = orderEntityMapper.get(customOrderEntity.getOrderId());
						if (orderEntity != null) {
							// 将订单数据放入对应总集合对象中
							orderList.add(orderEntity);
							// ---3---------------------------------------------------------------------------------------//
							// ---4---------------------------------------------------------------------------------------//
							// 获取款式信息数据
							StyleEntity styleEntity = styleEntityMapper.getStyleInfo(orderEntity.getStyleId().longValue());
							if (styleEntity != null) {
								// 将款式数据放入对应总集合对象中
								styleList.add(styleEntity);
								// ---4---------------------------------------------------------------------------------------//
								// ---5---------------------------------------------------------------------------------------//
								// 获取订单临时数据
								TempOrderTableEntity tempOrderTableEntity = tempOrderTableEntityMapper
										.getByOrderId(orderEntity.getOrderId().longValue());
								if (tempOrderTableEntity != null) {
									// 将订单临时数据放入对应总集合对象中
									tempOrderTableList.add(tempOrderTableEntity);
								}
								// ---5---------------------------------------------------------------------------------------//
								// ---6---------------------------------------------------------------------------------------//
								// 获取订单款式关联数据
								OrderStyleEntity orderStyle = orderStyleEntityMapper.getByOrderId(orderEntity.getOrderId().longValue());
								if (orderStyle != null) {
									// 将订单款式关联数据放入对应总集合对象中
									orderStyleList.add(orderStyle);
								}
								// ---6---------------------------------------------------------------------------------------//
								// ---7---------------------------------------------------------------------------------------//
								// 获取barCode数据集
								List<BarCodeEntity> barCodeTempList = barCodeEntityMapper
										.findListByBarCode(styleEntity.getStyleBarCode());
								if (barCodeTempList != null) {
									// 将barCode数据集放入对应总集合对象中
									barCodeList.addAll(barCodeTempList);
								}
								// ---7---------------------------------------------------------------------------------------//
								// ---8---------------------------------------------------------------------------------------//
								// 获取款式量体数据
								StyleFitEntity styleFit = styleFitEntityMapper.getFitInfo(styleEntity.getSysStyleId().longValue());
								if (styleFit != null) {
									// 将款式量体数据放入对应总集合对象中
									styleFitList.add(styleFit);
								}
								// ---8---------------------------------------------------------------------------------------//
								// ---9---------------------------------------------------------------------------------------//
								// 获取款式设计点数据集
								List<StyleOptionREntity> styleOptionTempList = styleOptionEntityMapper
										.findList(styleEntity.getSysStyleId().longValue());
								if (styleOptionTempList != null) {
									// 将款式设计点数据集放入对应总集合对象中
									//styleOptionList.addAll(styleOptionTempList);
									styleOptionMap.put(String.valueOf(styleEntity.getSysStyleId()), styleOptionTempList);
								}
								// ---9---------------------------------------------------------------------------------------//
								// ---10---------------------------------------------------------------------------------------//
								// 获取款式单耗数据集
								List<StyleMaterialEntity> styleMaterialTempList = styleMaterialEntityMapper
										.findList(styleEntity.getSysStyleId().longValue());
								if (styleMaterialTempList != null) {
									// 将款式单耗数据集放入对应总集合对象中
									//styleMaterialList.addAll(styleMaterialTempList);
									styleMaterialMap.put(String.valueOf(styleEntity.getSysStyleId()), styleMaterialTempList);
								}
								// ---10---------------------------------------------------------------------------------------//
								// ---11---------------------------------------------------------------------------------------//
								// 获取款式费用数据集
								List<StyleCostEntity> styleCostTempList = styleCostEntityMapper
										.findListByStyleId(styleEntity.getSysStyleId().longValue());
								if (styleCostTempList != null) {
									// 将款式费用数据集放入对应总集合对象中
									//styleCostList.addAll(styleCostTempList);
									styleCostMap.put(String.valueOf(styleEntity.getSysStyleId()), styleCostTempList);
								}
								// ---11---------------------------------------------------------------------------------------//
								// ---12---------------------------------------------------------------------------------------//
								// 获取款式工序数据集
								List<StyleOperatingEntity> styleOperatingTempList = styleOperatingEntityMapper
										.findList(styleEntity.getSysStyleId().longValue());
								if (styleOperatingTempList != null) {
									// 将款式工序数据集放入对应总集合对象中
									//styleOperatingList.addAll(styleOperatingTempList);
									styleOperatingMap.put(String.valueOf(styleEntity.getSysStyleId()), styleOperatingTempList);
								}
								// ---12---------------------------------------------------------------------------------------//
								// ---13---------------------------------------------------------------------------------------//
								// 获取款式质检数据集
								List<StyleQualityControlEntity> styleQualityControlTempList = styleQualityControlEntityMapper
										.findList(styleEntity.getSysStyleId().longValue());
								if (styleQualityControlTempList != null) {
									// 将款式质检数据集放入对应总集合对象中
									//styleQualityControlList.addAll(styleQualityControlTempList);
									styleQualityControlMap.put(String.valueOf(styleEntity.getSysStyleId()), styleQualityControlTempList);
								}
								// ---13---------------------------------------------------------------------------------------//
								logger.info("/-------数据读取-------" + DateUtils.getDate("yyyy-MM-dd HH:mm:ss") + "------------"
										+ orderEntity.getOrderNo() + "------------/");
							}
						}
					}
				}
			}
		}
		//
		returnMap.put("contractCustomList", contractCustomList);
		//
		returnMap.put("contractCustomOrderList", contractCustomOrderList);
		//
		returnMap.put("orderList", orderList);
		//
		returnMap.put("styleList", styleList);
		//
		returnMap.put("tempOrderTableList", tempOrderTableList);
		//
		returnMap.put("orderStyleList", orderStyleList);
		//
		returnMap.put("barCodeList", barCodeList);
		//
		returnMap.put("styleFitList", styleFitList);
		//
		//returnMap.put("styleOptionList", styleOptionList);
		returnMap.put("styleOptionMap",styleOptionMap);
		//
		//returnMap.put("styleMaterialList", styleMaterialList);
		returnMap.put("styleMaterialMap",styleMaterialMap);
		//
		//returnMap.put("styleCostList", styleCostList);
		returnMap.put("styleCostMap",styleCostMap);
		//
		//returnMap.put("styleOperatingList", styleOperatingList);
		returnMap.put("styleOperatingMap",styleOperatingMap);
		//
		//returnMap.put("styleQualityControlList", styleQualityControlList);
		returnMap.put("styleQualityControlMap",styleQualityControlMap);
		
		logger.info("/-------------------------数据读取-------------" + DateUtils.getDate("yyyy-MM-dd HH:mm:ss")
				+ "--------------结束--------------------------------------------------/");
		return returnMap;
	}

	/**
	 * 插入同步数据
	 * 
	 * @param dataMap
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	public void insertData(Map<String, Object> dataMap) throws Exception {
		logger.info("/-------------------------数据写入-------------" + DateUtils.getDate("yyyy-MM-dd HH:mm:ss")
				+ "--------------开始--------------------------------------------------/");
		if (dataMap != null && dataMap.size() > 0) {
			// 1.c_contract_custom_p
			List<ContractCustomEntity> contractCustomList = (List<ContractCustomEntity>) dataMap.get("contractCustomList");
			if (contractCustomList != null && contractCustomList.size() > 0) {
				contractCustomEntityMapper.insertList(contractCustomList);
				logger.info("/-------数据量:" + contractCustomList.size() + "---------------------contractCustomList---数据写入-------"
						+ DateUtils.getDate("yyyy-MM-dd HH:mm:ss") + "------------/");
			}
			// 2.c_contract_custom_order_r
			List<ContractCustomOrderEntity> contractCustomOrderList = (List<ContractCustomOrderEntity>) dataMap
					.get("contractCustomOrderList");
			if (contractCustomOrderList != null && contractCustomOrderList.size() > 0) {
				contractCustomOrderEntityMapper.insertList(contractCustomOrderList);
				logger.info("/-------数据量:" + contractCustomOrderList.size()
						+ "---------------------contractCustomOrderList---数据写入-------" + DateUtils.getDate("yyyy-MM-dd HH:mm:ss")
						+ "------------/");
			}
			// 3.o_order_p
			List<OrderEntity> orderList = (List<OrderEntity>) dataMap.get("orderList");
			if (orderList != null && orderList.size() > 0) {
				orderEntityMapper.insertList(orderList);
				logger.info("/------数据量:" + orderList.size() + "---------------------orderList---数据写入-------"
						+ DateUtils.getDate("yyyy-MM-dd HH:mm:ss") + "------------/");
			}
			// 4.s_style_p
			List<StyleEntity> styleList = (List<StyleEntity>) dataMap.get("styleList");
			if (styleList != null && styleList.size() > 0) {
				styleEntityMapper.insertList(styleList);
				logger.info("/------数据量:" + styleList.size() + "---------------------styleList---数据写入-------"
						+ DateUtils.getDate("yyyy-MM-dd HH:mm:ss") + "------------/");
			}
			// 5.temp_order_table
			List<TempOrderTableEntity> tempOrderTableList = (List<TempOrderTableEntity>) dataMap.get("tempOrderTableList");
			if (tempOrderTableList != null && tempOrderTableList.size() > 0) {
				tempOrderTableEntityMapper.insertList(tempOrderTableList);
				logger.info("/------数据量:" + tempOrderTableList.size() + "---------------------tempOrderTableList---数据写入-------"
						+ DateUtils.getDate("yyyy-MM-dd HH:mm:ss") + "------------/");
			}
			// 6.o_order_style_r
			List<OrderStyleEntity> orderStyleList = (List<OrderStyleEntity>) dataMap.get("orderStyleList");
			if (orderStyleList != null && orderStyleList.size() > 0) {
				orderStyleEntityMapper.insertList(orderStyleList);
				logger.info("/------数据量:" + orderStyleList.size() + "---------------------orderStyleList---数据写入-------"
						+ DateUtils.getDate("yyyy-MM-dd HH:mm:ss") + "------------/");
			}
			// 7.s_style_fit_r
			List<StyleFitEntity> styleFitList = (List<StyleFitEntity>) dataMap.get("styleFitList");
			if (styleFitList != null && styleFitList.size() > 0) {
				styleFitEntityMapper.insertList(styleFitList);
				logger.info("/------数据量:" + styleFitList.size() + "---------------------styleFitList---数据写入-------"
						+ DateUtils.getDate("yyyy-MM-dd HH:mm:ss") + "------------/");
			}
			// 13.a_bar_code_p
			List<BarCodeEntity> barCodeList = (List<BarCodeEntity>) dataMap.get("barCodeList");
			if (barCodeList != null && barCodeList.size() > 0) {
				barCodeEntityMapper.insertList(barCodeList);
				logger.info("/------数据量:" + barCodeList.size() + "---------------------barCodeList---数据写入-------"
						+ DateUtils.getDate("yyyy-MM-dd HH:mm:ss") + "------------/");
			}
			// 数据单条插入
			//insertListData(dataMap,styleList);
			// 数据集合插入
			insertMapData(dataMap,styleList);
		}
		logger.info("/-------------------------数据写入-------------" + DateUtils.getDate("yyyy-MM-dd HH:mm:ss")
				+ "--------------结束--------------------------------------------------/");
	}

	/**
	 * 数据集合插入
	 * @param dataMap
	 * @param styleList
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	public void insertMapData(Map<String, Object> dataMap,List<StyleEntity> styleList) throws Exception {
		logger.info("/--------------------------------------------------------Map集合数据写入---开始---------" + DateUtils.getDate("yyyy-MM-dd HH:mm:ss")+ "------------------/");
		if (styleList != null && styleList.size() > 0) {
			// 款式设计点数据
			Map<String, List<StyleOptionREntity>> styleOptionMap = (Map<String, List<StyleOptionREntity>>) dataMap.get("styleOptionMap");
			// 款式单耗数据
			Map<String, List<StyleMaterialEntity>> styleMaterialMap = (Map<String, List<StyleMaterialEntity>>) dataMap.get("styleMaterialMap");
			// 款式费用数据
			Map<String, List<StyleCostEntity>> styleCostMap = (Map<String, List<StyleCostEntity>>) dataMap.get("styleCostMap");
			// 款式工序数据
			Map<String, List<StyleOperatingEntity>> styleOperatingMap = (Map<String, List<StyleOperatingEntity>>) dataMap.get("styleOperatingMap");
			// 款式质检数据
			Map<String, List<StyleQualityControlEntity>> styleQualityControlMap = (Map<String, List<StyleQualityControlEntity>>) dataMap.get("styleQualityControlMap");
			for (int i = 0; i < styleList.size(); i++) {
				int count = i + 1;
				logger.info("/------数据量:" + styleList.size()+ "-----第"+count+"个------------------开始---------------" + DateUtils.getDate("yyyy-MM-dd HH:mm:ss")
				+ "------------/");
				StyleEntity styleEntity = styleList.get(i);
				// 8.s_style_option_r
				List<StyleOptionREntity> styleOptionList = styleOptionMap.get(String.valueOf(styleEntity.getSysStyleId()));
				if (styleOptionList != null && styleOptionList.size() > 0) {
					styleOptionEntityMapper.insertList(styleOptionList);
					logger.info("/------数据量:" + styleOptionList.size()+ "-----styleOptionList数据写入-----" + DateUtils.getDate("yyyy-MM-dd HH:mm:ss")+ "------/");
				}
				// 9.s_style_material_s
				List<StyleMaterialEntity> styleMaterialList = styleMaterialMap.get(String.valueOf(styleEntity.getSysStyleId()));
				if (styleMaterialList != null && styleMaterialList.size() > 0) {
					styleMaterialEntityMapper.insertList(styleMaterialList);
					logger.info("/------数据量:" + styleMaterialList.size()+ "-----styleMaterialList数据写入-----" + DateUtils.getDate("yyyy-MM-dd HH:mm:ss")+ "------/");
				}
				// 10.s_style_cost_s
				List<StyleCostEntity> styleCostList = styleCostMap.get(String.valueOf(styleEntity.getSysStyleId()));
				if (styleCostList != null && styleCostList.size() > 0) {
					styleCostEntityMapper.insertList(styleCostList);
					logger.info("/------数据量:" + styleCostList.size()+ "-----styleCostList数据写入-----" + DateUtils.getDate("yyyy-MM-dd HH:mm:ss")+ "------/");
				}
				// 11.s_style_operating_s
				List<StyleOperatingEntity> styleOperatingList = styleOperatingMap.get(String.valueOf(styleEntity.getSysStyleId()));
				if (styleOperatingList != null && styleOperatingList.size() > 0) {
					styleOperatingEntityMapper.insertList(styleOperatingList);
					logger.info("/------数据量:" + styleOperatingList.size()+ "-----styleOperatingList数据写入-----" + DateUtils.getDate("yyyy-MM-dd HH:mm:ss")+ "------/");
				}
				// 12.s_style_quality_control_p
				List<StyleQualityControlEntity> styleQualityControlList = styleQualityControlMap.get(String.valueOf(styleEntity.getSysStyleId()));
				if (styleQualityControlList != null && styleQualityControlList.size() > 0) {
					styleQualityControlEntityMapper.insertList(styleQualityControlList);
					logger.info("/------数据量:" + styleQualityControlList.size()+ "-----styleQualityControlList数据写入-----" + DateUtils.getDate("yyyy-MM-dd HH:mm:ss")+ "------/");
				}
				logger.info("/------数据量:" + styleList.size()+ "-----第"+count+"个------------------结束---------------" + DateUtils.getDate("yyyy-MM-dd HH:mm:ss")
				+ "------------/");
			}
		}
		logger.info("/--------------------------------------------------------Map集合数据写入---结束---------" + DateUtils.getDate("yyyy-MM-dd HH:mm:ss")+ "------------------/");
	}
	
	/**
	 * 数据单条插入
	 * @param dataMap
	 * @param styleList
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	public void insertListData(Map<String, Object> dataMap,List<StyleEntity> styleList) throws Exception {
		// 8.s_style_option_r
		List<StyleOptionREntity> styleOptionList = (List<StyleOptionREntity>) dataMap.get("styleOptionList");
		if (styleOptionList != null && styleOptionList.size() > 0) {
			logger.info("/------数据量:" + styleOptionList.size() + "---------------------styleOptionList---数据写入----开始---"
					+ DateUtils.getDate("yyyy-MM-dd HH:mm:ss") + "------------/");
			for (StyleOptionREntity sEntity : styleOptionList) {
				styleOptionEntityMapper.insertData(sEntity);
				logger.info("/-----styleOptionList:--" + sEntity.getSysStyleId() + "---------/");
			}
			logger.info("/------数据量:" + styleOptionList.size() + "---------------------styleOptionList---数据写入-----结束--"
					+ DateUtils.getDate("yyyy-MM-dd HH:mm:ss") + "------------/");
		}
		// 9.s_style_material_s
		List<StyleMaterialEntity> styleMaterialList = (List<StyleMaterialEntity>) dataMap.get("styleMaterialList");
		if (styleMaterialList != null && styleMaterialList.size() > 0) {
			logger.info("/------数据量:" + styleMaterialList.size() + "---------------------styleMaterialList---数据写入----开始---"
					+ DateUtils.getDate("yyyy-MM-dd HH:mm:ss") + "------------/");
			for (StyleMaterialEntity sEntity : styleMaterialList) {
				styleMaterialEntityMapper.insertData(sEntity);
				logger.info("/-----styleMaterialList:--" + sEntity.getStyleId() + "---------/");
			}
			logger.info("/------数据量:" + styleMaterialList.size() + "---------------------styleMaterialList---数据写入---结束----"
					+ DateUtils.getDate("yyyy-MM-dd HH:mm:ss") + "------------/");
		}
		// 10.s_style_cost_s
		List<StyleCostEntity> styleCostList = (List<StyleCostEntity>) dataMap.get("styleCostList");
		if (styleCostList != null && styleCostList.size() > 0) {
			logger.info("/------数据量:" + styleCostList.size() + "---------------------styleCostList---数据写入---开始----"
					+ DateUtils.getDate("yyyy-MM-dd HH:mm:ss") + "------------/");
			for (StyleCostEntity sEntity : styleCostList) {
				styleCostEntityMapper.insertData(sEntity);
				logger.info("/-----styleCostList:--" + sEntity.getStyleID() + "---------/");
			}
			logger.info("/------数据量:" + styleCostList.size() + "---------------------styleCostList---数据写入---结束----"
					+ DateUtils.getDate("yyyy-MM-dd HH:mm:ss") + "------------/");
		}
		// 11.s_style_operating_s
		List<StyleOperatingEntity> styleOperatingList = (List<StyleOperatingEntity>) dataMap.get("styleOperatingList");
		if (styleOperatingList != null && styleOperatingList.size() > 0) {
			logger
					.info("/------数据量:" + styleOperatingList.size() + "---------------------styleOperatingList---数据写入---开始----"
							+ DateUtils.getDate("yyyy-MM-dd HH:mm:ss") + "------------/");
			for (StyleOperatingEntity sEntity : styleOperatingList) {
				styleOperatingEntityMapper.insertData(sEntity);
				logger.info("/-----styleOperatingList:--" + sEntity.getStyleId() + "---------/");
			}
			logger
					.info("/------数据量:" + styleOperatingList.size() + "---------------------styleOperatingList---数据写入----结束---"
							+ DateUtils.getDate("yyyy-MM-dd HH:mm:ss") + "------------/");
		}
		// 12.s_style_quality_control_p
		List<StyleQualityControlEntity> styleQualityControlList = (List<StyleQualityControlEntity>) dataMap
				.get("styleQualityControlList");
		if (styleQualityControlList != null && styleQualityControlList.size() > 0) {
			logger.info("/------数据量:" + styleQualityControlList.size()
					+ "---------------------styleQualityControlList---数据写入---开始----" + DateUtils.getDate("yyyy-MM-dd HH:mm:ss")
					+ "------------/");
			for (StyleQualityControlEntity sEntity : styleQualityControlList) {
				styleQualityControlEntityMapper.insertData(sEntity);
				logger.info("/-----styleQualityControlList:--" + sEntity.getQcStyleId() + "---------/");
			}
			logger.info("/------数据量:" + styleQualityControlList.size()
					+ "---------------------styleQualityControlList---数据写入---结束----" + DateUtils.getDate("yyyy-MM-dd HH:mm:ss")
					+ "------------/");
		}
	}
	
	/**
	 * 更新同步状态
	 * @param contractCustomList
	 * @throws Exception
	 */
	public void updateSyncStatus(List<ContractCustomEntity> contractCustomList) throws Exception {
		if (contractCustomList != null) {
			for (ContractCustomEntity entity : contractCustomList) {
				contractCustomEntityMapper.updateSyncStatus(entity);
			}
		}
		logger.info("/-------更新同步状态-------" + DateUtils.getDate("yyyy-MM-dd HH:mm:ss") + "------------/");
	}
	
	
	public Map<String, Object> getStatusData(String date){
		Map<String, Object> returnMap = new HashMap<String, Object>();
		// 订单数据集
		List<OrderEntity> orderList = orderEntityMapper.findByUpdateDate(date);
		// 工序数据集
		List<StyleOperatingEntity> styleOperatingList = styleOperatingEntityMapper.findByUpdateDate(date);
		// 质检数据集
		List<StyleQualityControlEntity> styleQualityControlList = styleQualityControlEntityMapper.findByUpdateDate(date);
		// 质检返工数据集
		List<StyleQualityDetailsEntity> styleQualityDetailsList = styleQualityDetailsEntityMapper.findByCreateDate(date);
		// 工时数据集
		List<ProductionItemEntity> productionItemList = productionItemEntityMapper.findByCreateDate(date);
		//
		returnMap.put("orderList", orderList);
		returnMap.put("styleOperatingList", styleOperatingList);
		returnMap.put("styleQualityControlList", styleQualityControlList);
		returnMap.put("styleQualityDetailsList", styleQualityDetailsList);
		returnMap.put("productionItemList", productionItemList);
		return returnMap;
	}

	@SuppressWarnings("unchecked")
	public void updateData(Map<String, Object> dataMap) throws Exception {
		// 订单数据集
		List<OrderEntity> orderList = (List<OrderEntity>)dataMap.get("orderList");
		if (orderList != null && orderList.size() > 0) {
			for(OrderEntity orderEntity :orderList){
				orderEntityMapper.updateStatus(orderEntity);
			}
		}
		// 工序数据集
		List<StyleOperatingEntity> styleOperatingList = (List<StyleOperatingEntity>)dataMap.get("styleOperatingList");
		if (styleOperatingList != null && styleOperatingList.size() > 0) {
			for(StyleOperatingEntity styleOperatingEntity :styleOperatingList){
				styleOperatingEntityMapper.updateStatus(styleOperatingEntity);
			}
		}
		// 质检数据集
		List<StyleQualityControlEntity> styleQualityControlList = (List<StyleQualityControlEntity>)dataMap.get("styleQualityControlList");
		if (styleQualityControlList != null && styleQualityControlList.size() > 0) {
			for(StyleQualityControlEntity styleQualityControlEntity :styleQualityControlList){
				styleQualityControlEntityMapper.updateStatus(styleQualityControlEntity);
			}
		}
		// 质检返工数据集
		List<StyleQualityDetailsEntity> styleQualityDetailsList = (List<StyleQualityDetailsEntity>)dataMap.get("styleQualityDetailsList");
		if (styleQualityDetailsList != null && styleQualityDetailsList.size() > 0) {
			for(StyleQualityDetailsEntity styleQualityDetailsEntity :styleQualityDetailsList){
				styleQualityDetailsEntityMapper.insert(styleQualityDetailsEntity);
			}
		}
		// 工时数据集
		List<ProductionItemEntity> productionItemList = (List<ProductionItemEntity>)dataMap.get("productionItemList");
		if (productionItemList != null && productionItemList.size() > 0) {
			for(ProductionItemEntity productionItemEntity :productionItemList){
				productionItemEntityMapper.insert(productionItemEntity);
			}
		}
	}
}
